﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace First_Registry.Ioc
{
    /// <summary>
    /// IoC 容器类，管理类型的注册和解析
    /// </summary>
    public class IocContainer : IContainerExtension
    {
        private readonly Dictionary<Type, Type> _transientRegistrations = new Dictionary<Type, Type>();
        private readonly Dictionary<Type, object> _singletonInstances = new Dictionary<Type, object>();
        private readonly Dictionary<Type, Type> _singletonRegistrations = new Dictionary<Type, Type>();

        private readonly object _lock = new object();

        public IScopedProvider? CurrentScope => throw new NotImplementedException();

        public IScopedProvider CreateScope() => throw new NotImplementedException();

        public object Resolve(Type type) => throw new NotImplementedException();

        public object Resolve(Type type, params (Type Type, object Instance)[] parameters) => throw new NotImplementedException();

        public object Resolve(Type type, string name) => throw new NotImplementedException();

        public object Resolve(Type type, string name, params (Type Type, object Instance)[] parameters) => throw new NotImplementedException();

        public void RegisterTransient<TService, TImplementation>() where TImplementation : TService
        {
            _transientRegistrations[typeof(TService)] = typeof(TImplementation);
        }

        public void RegisterSingleton<TService, TImplementation>() where TImplementation : TService
        {
            _singletonRegistrations[typeof(TService)] = typeof(TImplementation);
        }

        public void RegisterInstance<TService>(TService instance)
        {
            _singletonInstances[typeof(TService)] = instance;
        }

        public void FinalizeExtension()
        {
            // 可选：在容器配置完成后，进行一些最终的设置
        }
    }
    /// <summary>
    /// 定义用于标记属性的注入特性
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class InjectAttribute : Attribute { }
}
